import { executor } from '../db'
import { ok, err } from '../res'
import { execCommand } from '../ssh'

export async function handlePingPong(event, arg) {
  try {
    const res1 = await executor('select * from users where userName = :userName limit 1 ', {
      replacements: {
        userName: arg
      }
    })
    const res2 = await execCommand('server1', 'ls')
    const res = res1 + res2
    return ok(res)
  } catch (error) {
    console.log(error.message)
    return err(error.message)
  }
}

export const pingPongHandlers = {
  'ping:pong': handlePingPong
}
